package cn.fl.product.verify;

import java.util.List;

import org.springframework.util.StringUtils;

import cmm.mid.core.framework.page.KeyValueVO;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.lb.framework.poi.excel.entity.result.ExcelVerifyHanlderResult;
import cn.lb.framework.poi.handler.inter.IExcelVerifyHandler;

/**
 * 列数据自定义校验，实现IExcelVerifyHandler接口
 * Created by Administrator on 2016/5/10.
 */
@SuppressWarnings("rawtypes")
public class VerifyMfr implements IExcelVerifyHandler {

	private List<KeyValueVO> mfrKVList;
	
	
    public VerifyMfr(List<KeyValueVO> mfrKVList) {
		super();
		this.mfrKVList = mfrKVList;
	}
	/**
     * 导入校验方法
     * @param obj 当前对象
     * @param name 列名
     * @param value 值
     * @return
     */
    @Override
    public ExcelVerifyHanlderResult verifyHandler(Object obj, String name, Object value) {
    	
    	if("所属厂商名称".equals(name)){
    		String val = (String) value;
    		String newVal = val.trim();	
    		newVal = StringUtils.replace(newVal, "（", "(");
    		newVal = StringUtils.replace(newVal, "）", ")");
    		
    		//查询所有厂商进行匹配 
    		if(CollectionUtils.isNotEmpty(mfrKVList)){
    			int sum = 0;
    			for (KeyValueVO kv : mfrKVList) {
					if(kv.getValue().equals(newVal)){
						sum++;
					}
				}
    			if(sum==0){
    				return new ExcelVerifyHanlderResult(false, "该厂商不存在");
    			}
    		}
    	}
    	
        return new ExcelVerifyHanlderResult(true);
    }
    
    
	public List<KeyValueVO> getMfrKVList() {
		return mfrKVList;
	}
	public void setMfrKVList(List<KeyValueVO> mfrKVList) {
		this.mfrKVList = mfrKVList;
	}

}
